package leo.weixin.entity.material;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 *图文素材的封装
 * 参数	是否必须	说明
 * title	是	标题
 * thumb_media_id	是	图文消息的封面图片素材id（必须是永久mediaID）
 * author	否	作者
 * digest	否	图文消息的摘要，仅有单图文消息才有摘要，多图文此处为空。如果本字段为没有填写，则默认抓取正文前64个字。
 * show_cover_pic	是	是否显示封面，0为false，即不显示，1为true，即显示
 * content	是	图文消息的具体内容，支持HTML标签，必须少于2万字符，小于1M，
 *     且此处会去除JS,涉及图片url必须来源 "上传图文消息内的图片获取URL"接口获取。外部图片url将被过滤。
 * content_source_url	是	图文消息的原文地址，即点击“阅读原文”后的URL
 * need_open_comment	否	Uint32 是否打开评论，0不打开，1打开
 * only_fans_can_comment	否	Uint32 是否粉丝才可评论，0所有人可评论，1粉丝才可评论
 */
@Data
@Accessors(chain = true)
public class Article {
    private String title;
    @JSONField(name = "thumb_media_id")
    private String thumbMediaId;
    private String author;  //否
    private String digest;  //否
    @JSONField(name = "show_cover_pic")
    private Integer showCoverPic;
    private String content;
    @JSONField(name = "content_source_url")
    private String contentSourceUrl;
    @JSONField(name = "need_open_comment")
    private Integer needOpenComment;   //否
    @JSONField(name = "only_fans_can_comment")
    private Integer onlyFansCanComment;  //否

    public Article setNeedOpenComment(boolean needOpenComment) {
        this.needOpenComment = needOpenComment ? 1 : 0;
        return this;
    }

    public Article setOnlyFansCanComment(boolean onlyFansCanComment) {
        this.onlyFansCanComment = onlyFansCanComment ? 1 : 0;
        return this;
    }

    public static ArticleBuilder builder(){
        return new ArticleBuilder();
    }
    private Article(){}

    public static class ArticleBuilder{
        private Article article;
        private ArticleBuilder(){
            article = new Article();
        };
        public ArticleBuilder title(String title){
            article.title = title;
            return this;
        }
        public ArticleBuilder thumbMediaId(String thumbMediaId){
            article.thumbMediaId = thumbMediaId;
            return this;
        }
        public ArticleBuilder showCoverPic(boolean showCoverPic){
            article.showCoverPic = showCoverPic ? 1 : 0;
            return this;
        }
        public ArticleBuilder content(String content){
            article.content = content;
            return this;
        }
        public ArticleBuilder contentSourceUrl(String contentSourceUrl){
            article.contentSourceUrl = contentSourceUrl;
            return this;
        }
        public Article build(){
            return article;
        }
    }
}
